package cn.edu.ujn.park.service;

import cn.edu.ujn.park.dao.Equipment;
import cn.edu.ujn.park.dao.EquipmentMapper;
import cn.edu.ujn.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EquipmentServiceImpl implements IEquipmentService{
    @Autowired
    private EquipmentMapper equipmentMapper;
    @Override
    public List<Equipment> selectAll() {
        return equipmentMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey1(Equipment equipment) {
        return equipmentMapper.updateByPrimaryKey1(equipment);
    }

    @Override
    public int deleteByPrimaryKey(Integer equipmentId) {
        return equipmentMapper.deleteByPrimaryKey(equipmentId);
    }

    @Override
    public int insert(Equipment row) {
        return equipmentMapper.insert(row);
    }

    @Override
    public Page<Equipment> selectAll1(Equipment equipment) {
        Page<Equipment> page = new Page<>();
        List<Equipment> equipment1 = equipmentMapper.selectAll1(equipment);
        page.setPage(equipment.getStart());
        page.setRows(equipment1);
        page.setSize(equipment.getRows());
        page.setTotal(equipmentMapper.selectCount());
        return page;
    }

    @Override
    public Page<Equipment> selectByName(Equipment equipment) {
        Page<Equipment> page = new Page<>();
        List<Equipment> equipment1 = equipmentMapper.selectByName(equipment);
        page.setPage(equipment.getStart());
        page.setRows(equipment1);
        page.setSize(equipment.getRows());
        page.setTotal(equipmentMapper.selectCountByName(equipment.getEquipmentName()));
        return page;
    }
}
